//
// Created by Win10 on 2022/10/31.
//

#include<iostream>
#include "sql_stack.h"

using namespace std;

bool InitStack(LiStack &S) {
    S = nullptr;
    return true;
}

bool StackEmpty(LiStack S) {
    if (S == nullptr) return true;
    return false;
}

bool Push(LiStack &S, ElemType x) {
    auto p = (LinkNode *) malloc(sizeof(LinkNode));
    if (p == nullptr) return false;
    p->data = x;
    p->next = S;
    S = p;
    return true;
}

bool Pop(LiStack &S, ElemType &x) {
    if (StackEmpty(S)) return false;
    LinkNode *p = S;
    S = S->next;
    x = p->data;
    free(p);
    return true;
}

bool GetTop(LiStack S, ElemType &x) {
    if (StackEmpty(S)) {
        return false;
    }
    x = S->data;
    return true;
}

bool DestoryStack(LiStack &S) {
    while (S != nullptr) {
        LinkNode *p = S;
        S = S->next;
        free(p);
    }
    free(S);
    S = nullptr;
    return true;
}

int main() {
    {
        LiStack S;
        InitStack(S);
        for (int i = 0; i <= 5; i++) {
            Push(S, i);
        }
        ElemType x;
        GetTop(S, x);
        cout << x << endl;
        while (!StackEmpty(S)) {
            Pop(S, x);
            cout << x << endl;
        }
    }
    test();
    return 0;
}